//package org.ricks.kcp;
//
//import org.ricks.ioc.Ricks;
//import org.ricks.common.utils.RandomUtils;
//import org.ricks.boot.utils.TimeUtils;
//import org.ricks.net.DataCodecKit;
//import org.ricks.net.buffer.BufferPagePool;
//import org.ricks.net.transport.Worker;
//import org.ricks.net.transport.kcp.KcpBootstrap;
//import org.ricks.net.transport.kcp.KcpChannel;
//import org.ricks.net.transport.kcp.KcpSession;
//
//import java.io.IOException;
//import java.net.InetSocketAddress;
//import java.nio.ByteBuffer;
//import java.nio.ByteOrder;
//
///**
// * @Author ricks
// * @Version [v1.0]
// * @CreateTime 2024-05-13   17:04
// * @Description TODO
// */
//public class KcpRun {
//
//    public static void main(String[] args) throws IOException {
//        BufferPagePool bufferPagePool = new BufferPagePool(1024 * 1024 * 16, Runtime.getRuntime().availableProcessors(), true);
//
//        Worker worker = new Worker(bufferPagePool, Runtime.getRuntime().availableProcessors());
//
////        Ricks.run(RobotBootstrap.class);//启动容器 & 启动server
//        DataCodecKit.setDataCodec(new GameCodec());
//        KcpExternalProtocol protocol = new KcpExternalProtocol();
//        RobotHandler handler = new RobotHandler();
//        InetSocketAddress socketAddress = new InetSocketAddress("192.168.27.46", 10012);
//
//        KcpBootstrap bootstrap = new KcpBootstrap(protocol, handler, worker);
//
//        bootstrap.setBannerEnabled(false)
//                .setThreadNum(Runtime.getRuntime().availableProcessors())
//                .setBufferPagePool(bufferPagePool)
//                .setReadBufferSize(1024 * 2048);
//        KcpChannel channel = (KcpChannel) bootstrap.open();
//        int conv = (int )TimeUtils.now() /1000;
//        KcpSession session = channel.createAndCacheSession(socketAddress, conv);
//
//        try {
//
//            int headLength = 8;
//            //游戏默认是小端
//            ByteBuffer byteBuffer = ByteBuffer.allocate(headLength).order(ByteOrder.LITTLE_ENDIAN);
////            byteBuffer.putShort((short) 10001);
////            byteBuffer.putInt(1);
////            byte[] bytes = RandomUtils.randomBytes(2000);
////            byteBuffer.put(bytes);
//            byteBuffer.putLong(8888);
//
//            byteBuffer.flip();
//            byte[] data = new byte[headLength];
//            byteBuffer.get(data);
//
//            for (int i1 = 0; i1 < 100000; i1++) {
//                session.send(data);
//                Thread.sleep(1000);
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}
